package com.mh.domain;

import java.io.Serializable;
import java.util.Date;
import java.util.Set;

import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import javax.xml.bind.annotation.XmlType;

import org.codehaus.jackson.annotate.JsonIgnore;
import org.codehaus.jackson.map.annotate.JsonDeserialize;
import org.codehaus.jackson.map.annotate.JsonSerialize;
import org.hibernate.validator.constraints.NotEmpty;

import com.mh.web.utils.DateJsonDeserializer;
import com.mh.web.utils.DateJsonSerializer;

/**
 * 
 * @ModelCoreReference [platform:/resource/demo-mh/.springDSL/com/mh/domain/Invoice.datatype]
 */

@Entity
@NamedQueries({
		@NamedQuery(name = "findAllInvoices", query = "select myInvoice from Invoice myInvoice"),
		@NamedQuery(name = "findInvoiceByCreatedBy", query = "select myInvoice from Invoice myInvoice where myInvoice.createdBy = ?1"),
		@NamedQuery(name = "findInvoiceByCreatedByContaining", query = "select myInvoice from Invoice myInvoice where myInvoice.createdBy like ?1"),
		@NamedQuery(name = "findInvoiceByCreatedOn", query = "select myInvoice from Invoice myInvoice where myInvoice.createdOn = ?1"),
		@NamedQuery(name = "findInvoiceByDocument", query = "select myInvoice from Invoice myInvoice where myInvoice.document = ?1"),
		@NamedQuery(name = "findInvoiceByDocumentContaining", query = "select myInvoice from Invoice myInvoice where myInvoice.document like ?1"),
		@NamedQuery(name = "findInvoiceById", query = "select myInvoice from Invoice myInvoice where myInvoice.id = ?1"),
		@NamedQuery(name = "findInvoiceByModifiedBy", query = "select myInvoice from Invoice myInvoice where myInvoice.modifiedBy = ?1"),
		@NamedQuery(name = "findInvoiceByModifiedByContaining", query = "select myInvoice from Invoice myInvoice where myInvoice.modifiedBy like ?1"),
		@NamedQuery(name = "findInvoiceByModifiedOn", query = "select myInvoice from Invoice myInvoice where myInvoice.modifiedOn = ?1"),
		@NamedQuery(name = "findInvoiceByPrimaryKey", query = "select myInvoice from Invoice myInvoice where myInvoice.id = ?1"),
		@NamedQuery(name = "findInvoiceByTotal", query = "select myInvoice from Invoice myInvoice where myInvoice.total = ?1") })
@Table(schema = "MHTEST", name = "INVOICE")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(namespace = "demo-mh/com/mh/domain", name = "Invoice")
@XmlRootElement(namespace = "demo-mh/com/mh/domain")
public class Invoice implements Serializable {
	private static final long serialVersionUID = 1L;

	/**
	 */

	@Column(name = "ID", nullable = false)
	@Basic(fetch = FetchType.EAGER)
	@Id
	@XmlElement
	@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seq_invoice")
	@SequenceGenerator(name = "seq_invoice", sequenceName = "seq_invoice")
	Integer id;

	/**
	 */

	@Column(name = "DOCUMENT", length = 20, nullable = false)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	@NotNull
	@NotEmpty
	@Size(max=20,  message="{com.vit.tamanho.maximo}")
	String document;

	/**
	 */

	@Column(name = "TOTAL", scale = 2, precision = 16, nullable = false)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	@NotNull
	Double total;

	/**
	 */

	@Column(name = "CREATED_BY", length = 30, nullable = false)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	@NotNull
	@NotEmpty
	@Size(max=30,  message="{com.vit.tamanho.maximo}")
	String createdBy;

	/**
	 */
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "CREATED_ON", nullable = false)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	@NotNull
	Date createdOn;

	/**
	 */

	@Column(name = "MODIFIED_BY", length = 30)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	@Size(max=30,  message="{com.vit.tamanho.maximo}")
	String modifiedBy;

	/**
	 */
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "MODIFIED_ON")
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	Date modifiedOn;

	/**
	 */
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumns({ @JoinColumn(name = "CUSTOMER_ID", referencedColumnName = "ID") })
	@XmlTransient
	Customer customer;

	/**
	 */
	@OneToMany(mappedBy = "invoice", cascade = { CascadeType.REMOVE }, fetch = FetchType.LAZY)
	@XmlElement(name = "", namespace = "")
	java.util.Set<com.mh.domain.Item> items;

	/**
	 */
	public void setId(Integer id) {
		this.id = id;
	}

	/**
	 */

	public Integer getId() {
		return this.id;
	}

	/**
	 */
	public void setDocument(String document) {
		this.document = document;
	}

	/**
	 */
	public String getDocument() {
		return this.document;
	}

	/**
	 */
	public void setTotal(Double total) {
		this.total = total;
	}

	/**
	 */
	public Double getTotal() {
		return this.total;
	}

	/**
	 */
	public void setCreatedBy(String createdBy) {
		this.createdBy = createdBy;
	}

	/**
	 */
	
	public String getCreatedBy() {
		return this.createdBy;
	}	

	/**
	 */
	@JsonDeserialize(using=DateJsonDeserializer.class)
	public void setCreatedOn(Date createdOn) {
		this.createdOn = createdOn;
	}

	/**
	 */
	@JsonSerialize(using=DateJsonSerializer.class)
	public Date getCreatedOn() {
		return this.createdOn;
	}

	/**
	 */
	public void setModifiedBy(String modifiedBy) {
		this.modifiedBy = modifiedBy;
	}

	/**
	 */
	public String getModifiedBy() {
		return this.modifiedBy;
	}

	/**
	 */
	@JsonDeserialize(using=DateJsonDeserializer.class)
	public void setModifiedOn(Date modifiedOn) {
		this.modifiedOn = modifiedOn;
	}

	/**
	 */
	@JsonSerialize(using=DateJsonSerializer.class)
	public Date getModifiedOn() {
		return this.modifiedOn;
	}

	/**
	 */
	@JsonIgnore
	public void setCustomer(Customer customer) {
		this.customer = customer;
	}

	/**
	 */
	@JsonIgnore
	public Customer getCustomer() {
		return customer;
	}

	/**
	 */
	public void setItems(Set<Item> items) {
		this.items = items;
	}

	/**
	 */
	@JsonIgnore
	public Set<Item> getItems() {
		if (items == null) {
			items = new java.util.LinkedHashSet<com.mh.domain.Item>();
		}
		return items;
	}

	/**
	 */
	public Invoice() {
	}

	/**
	 * Copies the contents of the specified bean into this bean.
	 *
	 */
	public void copy(Invoice that) {
		setId(that.getId());
		setDocument(that.getDocument());
		setTotal(that.getTotal());
		setCreatedBy(that.getCreatedBy());
		setCreatedOn(that.getCreatedOn());
		setModifiedBy(that.getModifiedBy());
		setModifiedOn(that.getModifiedOn());
		setCustomer(that.getCustomer());
		setItems(new java.util.LinkedHashSet<com.mh.domain.Item>(that.getItems()));
	}

	/**
	 * Returns a textual representation of a bean.
	 *
	 */
	public String toString() {

		StringBuilder buffer = new StringBuilder();

		buffer.append("id=[").append(id).append("] ");
		buffer.append("document=[").append(document).append("] ");
		buffer.append("total=[").append(total).append("] ");
		buffer.append("createdBy=[").append(createdBy).append("] ");
		buffer.append("createdOn=[").append(createdOn).append("] ");
		buffer.append("modifiedBy=[").append(modifiedBy).append("] ");
		buffer.append("modifiedOn=[").append(modifiedOn).append("] ");

		return buffer.toString();
	}

	/**
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = (int) (prime * result + ((id == null) ? 0 : id.hashCode()));
		return result;
	}

	/**
	 */
	public boolean equals(Object obj) {
		if (obj == this)
			return true;
		if (!(obj instanceof Invoice))
			return false;
		Invoice equalCheck = (Invoice) obj;
		if ((id == null && equalCheck.id != null) || (id != null && equalCheck.id == null))
			return false;
		if (id != null && !id.equals(equalCheck.id))
			return false;
		return true;
	}
}
